# Author    :Dun_Hz
# Time      :2024/3/15 14:07
# 找出一个列表中的最大值和最小值
class Max_Min():
    def __init__(self):
        self.max=None
        self.min=None

    def getMax(self):
        return self.max

    def getMin(self):
        return self.min

    def getMaxandMin(self,li):
        if li ==None:
            print('参数不合法')
            return
        lens= len(li)
        print(lens)
        # 两两分组，较小值放左边，较大值放右边
        i = 0
        while i < (lens-1):
            if li[i]>li[i+1]:
                li[i],li[i+1]=li[i+1],li[i]
            i += 2
        print(li)
        #在各个分组左半部分找最小值
        self.min = li[0]
        i = 2
        while i< lens:
            if li[i]<self.min:
                self.min = li[i]
            i += 2
        #在各个分组右半部分找最大值
        self.max = li[1]
        i = 3
        while i< lens:
            if li[i]>self.max:
                self.max = li[i]
            i += 2
        # 如果元素是奇数，最后一个元素单独处理
        if li[-1]>self.max:
            self.max = li[-1]

if __name__ =='__main__':
    test_li = [7,13,49,6,3,1,50]
    m = Max_Min()
    m.getMaxandMin(test_li)
    print("max="+str(m.getMax()))
    print("min="+str(m.getMin()))